﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ShredTheLog.Common.MVVM;
using Microsoft.Win32;

namespace ShredTheLog.Controls
{
    public sealed class FilePicker : ControlBase
    {
        static FilePicker()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(FilePicker), new FrameworkPropertyMetadata(typeof(FilePicker)));
        }

        public FilePicker()
        {
            BrowseCommand = new DelegateCommand(
                () =>
                {
                    var dlg = new OpenFileDialog() { FileName = Value };
                    if (dlg.ShowDialog() == true) Value = dlg.FileName;
                }, () => !IsReadOnly);
        }

        public string Value
        {
            get { return (string)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(FilePicker));

        public ICommand BrowseCommand
        {
            get { return (ICommand)GetValue(BrowseCommandProperty); }
            set { SetValue(BrowseCommandProperty, value); }
        }
        public static readonly DependencyProperty BrowseCommandProperty = DependencyProperty.Register("BrowseCommand", typeof(ICommand), typeof(FilePicker));
    }
}
